package com.hushao.aimi.repository;

import com.hushao.aimi.entity.AimiUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * @description: 用户操作方法
 * @author: 胡少
 * @create: 2018-06-03 21:29
 **/
public interface UserRepository extends JpaRepository<AimiUser,String> {


    @Query(value = "select u.id,u.username,u.phone,u.email,u.status,r.role_id,u.create_time,u.update_time from aimi_user AS u " +
            "left join user_role as r on u.id=r.user_id where u.username like:username ",
            countQuery = "select count(*) from aimi_user As u left join user_role as r on u.id=r.id where u.username like:username",
            nativeQuery = true)
    Page<Object> findUserByUsernameLike(@Param("username") String username, Pageable pageable);

    /**
     * 根据账号查询用户
     * @param username
     * @return
     */
    AimiUser findByUsername(String username);
}
